<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
?>
	<div class="row">
		<div class="col-lg-12">
			<ul class="shortcut-buttons-set">
				<li>
					<a class="shortcut-button" href='#request_list'><span>
					<i class="aicon-task_list"></i>
					<?php echo $this->language['list'];?></span></a>
				</li>
				<li>
					<a class="shortcut-button" href='#request_list/status=0'><span>
					<i class="aicon-clock"></i>
					<?php echo $this->language['waiting'];?></span></a>
				</li>
				<li>
					<a class="shortcut-button" href='#request_create' ><span>
					<i class="aicon-plus"></i>
					<?php echo $this->language['request_create'];?></span></a>
				</li>
				<?php if(check_permission('request_view')): ?>
				<li>
					<a class="shortcut-button" href='#request_report'><span>
					<i class="aicon-chart"></i>
					Xem báo cáo</span></a>
				</li>
				<?php endif;?>
			</ul>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-task_list"></i> <?php echo $this->language['list'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:doFilterReq();" id="request_filter" class="form-horizontal" role="form">
						<div class="form-group">
							<label class="col-lg-2 control-label">Lọc phiếu : </label>
							<div class="col-lg-10">
								<div class="form-inline">
									<div class="form-group">
										<input type="text" class="form-control" id="filter_from" name="from" value="<?php echo (isset($_GET['from'])) ? $_GET['from'] : '';?>" placeholder="Từ ngày">
										<input type="text" class="form-control" id="filter_to" name="to" value="<?php echo (isset($_GET['to'])) ? $_GET['to'] : '';?>" placeholder="Đến ngày">
									</div>
									<div class="form-group">
										<select class="form-control" id="filter_status" name="status">
											<option value="">--- Tất cả ---</option>
											<option value="0">Chờ duyệt</option>
											<option value="1">Đã duyệt - chưa chi</option>
											<option value="2">Đã duyệt - đã chi</option>
											<option value="3">Đã hoàn ứng</option>
										</select>
									</div>
									<div class="form-group">
										<button type="submit" class="btn btn-danger"><i class="icon-search"></i> lọc kết quả</button>
									</div>
								</div>
							</div>
						</div>
					</form>
					<hr>
		            <table class="table table-fixed table-hover table-condensed">
						<thead>
							<tr>
								<th width='20px'>&nbsp;</th>
								<th width='70px'>Mã số</th>
								<th width='130px'>Họ và tên</th>
								<th>Lý do</th>
								<th width='85px'>Số tiền</th>
								<th width='80px'>Ngày tạo</th>
								<th width='110px'>Tình trạng</th>
								<th width='50px'>&nbsp;</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->requests as $row){ ?>
							<tr>
								<td><?php echo $row['attach'];?></td>
								<td><a href='#request_view/id=<?php echo $row['req_id'];?>'><?php echo $row['req_code'];?></a></td>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $_SESSION['user_data'][$row['uId']]['fullname'];?></a></td>
								<td><a href='#request_view/id=<?php echo $row['req_id'];?>'><?php echo $row['req_reason'];?></a></td>
								<td><font color=red><?php echo number_format($row['amount'],0,'',',');?></font></td>
								<td><?php echo date("d/m/Y",$row['req_date']);?></td>
								<td>
								<?php
									if($row['req_signature1']=='0') echo "<font color=red>Chờ Duyệt</font>";
									elseif($row['req_status']=='0') echo "<font color=green>Đã Duyệt</font> - <font color=red>Chưa Chi</font>";
									elseif($row['req_status']=='1') echo "<font color=green>Đã Duyệt</font> - <font color=green>Đã Chi</font>";
									elseif($row['req_status']=='2') echo "<font color=blue>Đã Hoàn Thành</font>";
									else echo "<font color=purple>Không biết</font>";
								?>
								</td>
								<td>
									<a href='#request_view/id=<?php echo $row['req_id'];?>'><img src="resources/images/icons/view.png" /></a>
									<a href='javascript:;' onClick="deletePTU('<?php echo $row['req_code'];?>');"><img src="resources/images/icons/cross.png" /></a>
								</td>
							</tr>
							<?php } ?>
							<tr>
								<td colspan="4" class="text-right"><b>Tổng chưa duyệt :</b></td>
								<td colspan="3"><font color=red><?php echo number_format($this->stastics['chua_duyet'],0,'',',');?></font></td>
							</tr>
							<tr>
								<td colspan="4" class="text-right"><b>Tổng chưa chi :</b></td>
								<td colspan="3"><font color=red><?php echo number_format($this->stastics['da_duyet'],0,'',',');?></font></td>
							</tr>
							<tr>
								<td colspan="4" class="text-right"><b>Tổng đã chi :</b></td>
								<td colspan="3"><font color=red><?php echo number_format($this->stastics['da_chi'],0,'',',');?></font></td>
							</tr>
							<tr>
								<td colspan="4" class="text-right"><b>Tổng đã hoàn ứng :</b></td>
								<td colspan="3"><font color=red><?php echo number_format($this->stastics['da_hoan_ung'],0,'',',');?></font></td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script>
		$(function() {
			$( "#filter_from" ).datepicker({ dateFormat: 'dd-mm-yy' });
			$( "#filter_to" ).datepicker({ dateFormat: 'dd-mm-yy' });
		});
	</script>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>